package com.pucheng.bracelet.ui.fragment.gpsrun

//import com.pucheng.bracelet.app.dispatcher.GpsRunPermissionsDispatcher
import android.content.Intent
import android.os.Bundle
import android.view.View
import com.blankj.utilcode.util.ToastUtils
import com.pucheng.bracelet.R
import com.pucheng.bracelet.app.dispatcher.RunCountTimer
import com.pucheng.bracelet.ui.activity.gpsrun.GpsRunningActivity
import com.pucheng.bracelet.viewmodel.gpsrun.GpsRunViewModel
import kotlinx.android.synthetic.main.fragment_gps_run.*
import me.hgj.jetpackmvvm.base.fragment.BaseVmFragment
import me.hgj.jetpackmvvm.demo.app.ext.showMessage
import me.hgj.jetpackmvvm.demo.app.ext.showMessageNoTiltle
import me.hgj.jetpackmvvm.demo.app.ext.startAppSetting

class GpsRunFragment : BaseVmFragment<GpsRunViewModel>() {
    override fun createObserver() {

    }

    override fun dismissLoading() {
    }

    override fun initView(savedInstanceState: Bundle?) {
        //开始跑步按钮˛
        tv_run_start.setOnClickListener {
            if (isAdded) {
                showMessageNoTiltle(
                    getString(R.string.enable_gps_hint),
                    getString(R.string.continue_run),
                    { startRun() })
            }
        }
    }

    override fun layoutId(): Int = R.layout.fragment_gps_run

    override fun lazyLoadData() {
    }

    override fun showLoading(message: String) {
    }

    fun startRun() {
        this.tv_run_start.visibility = View.GONE
        this.tv_gps_state.visibility = View.GONE
        this.tv_run_countdown.visibility = View.VISIBLE
        val bVar = RunCountTimer(3)
        bVar.showTextView(this.tv_run_countdown)
        bVar.isSecond(true)
        bVar.setCountdownCallnack {
            if (isAdded) {
                startActivity(Intent(mActivity, GpsRunningActivity::class.java))
                mActivity.finish()
            }
        }
        bVar.mo18908r()
//        this.runCountTimer = bVar
    }


    private fun showGPSPermissionsDialog(message: String) {
        if (isAdded) {
            showMessage(
                message,
                "",
                getString(R.string.allow),
                { startAppSetting(mActivity) },
                getString(R.string.deny)
            )
        }
    }
}